<%@page import="service.Constan"%>
<%@page import="service.implement.ProjectDAO"%>
<%@page import="model.Project"%>
<%@page import="service.implement.EmployeeDAO"%>
<%@page import="model.Employee"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.Timesheet"%>
<%@page import="service.implement.TimesheetDAO"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
	function validateForm() {
		var date = document.forms["form"]["date"].value;
		var duration = document.forms["form"]["duration"].value;
		var description = document.forms["form"]["description"].value;
		var activity = document.forms["form"]["activity"].value;
		if (date == "") {
			alert("Date khong duoc de trong");
			return false;
		}
		if (duration == "") {
			alert("Duration khong duoc de trong");
			return false;
		}
		if (description == "") {
			alert("Description khong duoc de trong");
			return false;
		}
	}
</script>
</head>
<body>
	<%@ include file="Menu.jsp"%>
	<%
		int id1 = Integer.parseInt(request.getParameter("checkTimesheet"));

		TimesheetDAO dao = new TimesheetDAO();
		Timesheet ts = dao.getTimesheetById(id1);

		ArrayList<Employee> list = new EmployeeDAO().getEmployee();
		int id2 = ts.getEmployeeid();
		Employee em = new EmployeeDAO().getEmployeeById(id2);
	%>
	<%
		ArrayList<Project> list1 = new ProjectDAO().getProject();
		int id3 = ts.getProjectid();
		Project pj = new ProjectDAO().getProjectById(id3);
	%>
	<div class="panel panel-default">
		<!-- Default panel contents -->
		<div class="panel-heading">Update Timesheet</div>
		<br>
		<form class="form-horizontal" action="doupdateTimesheet" method="post"
			name="form" onsubmit="return validateForm()">
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Id</label>
				<div class="col-sm-10">
					<input type="text" name="id2" value="<%=ts.getId()%>" readonly />
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Employee</label>
				<div class="col-sm-10">
					<select name="employeeid">

						<%
							for (Employee e : list) {
								if (id2 == e.getId()) {
						%>
						<option selected value=<%=e.getId()%>><%=e.getName()%></option>

						<%
							} else {
						%>
						<option value=<%=e.getId()%>><%=e.getName()%></option>
						<%
							}
							}
						%>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Project</label>
				<div class="col-sm-10">
					<select name="projectid">

						<%
							for (Project p : list1) {
								if (id3 == p.getId()) {
						%>
						<option selected value="<%=p.getId()%>"><%=p.getNameProject()%></option>
						<%
							} else {
						%>
						<option value="<%=p.getId()%>"><%=p.getNameProject()%></option>
						<%
							}
							}
						%>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Date</label>
				<div class="col-sm-10">
					<input type="date" name="date" value="<%=ts.getDate()%>" />
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Duration</label>
				<div class="col-sm-10">
					<input type="number" name="duration" value="<%=ts.getDuration()%>" />
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Description</label>
				<div class="col-sm-10">
					<input type="text" name="description"
						value="<%=ts.getDescription()%>" />
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Activity</label>
				<div class="col-sm-10">
					<input type="text" name="activity" value="<%=ts.getActivity()%>" />

				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Overtime</label>
				<div class="col-sm-10">
					<select name="overtime">
					<%
					if(ts.getOvertime()==Constan.SER_STATUS_TRUE){
					%>
						<option><%=ts.getOvertime()%></option>
						<option value=<%=Constan.SER_STATUS_TRUE%>>YES</option>
						<option value=<%=Constan.SER_STATUS_FALSE%>>NO</option>
					<%} %>	
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Location</label>
				<div class="col-sm-10">
					<select name="location">
						<option selected value=<%=ts.getLocation() %>><%=ts.getLocation()%></option>
						<option value=<%=Constan.LOCATION_THNC%>>THNC</option>
						<option value=<%=Constan.LOCATION_HN%>>Ha Noi</option>
						<option value=<%=Constan.LOCATION_HCM%>>HCM</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label"></label>
				<div class="col-sm-10">
					<input type="submit" name="nhap" value="Update" />
				</div>
			</div>
		</form>
	</div>
</body>
</html>